﻿using Framework.Core.Enums;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using my.abp.Application.Contracts.Dtos.Dict;
using my.abp.Application.Contracts.IServices.Dict;
using my.abp.Domain.IManagers.Dict;
using my.abp.Domain.Managers.Dict;
using my.abp.Domain.Shared.Entities;
using my.abp.Domain.Shared.Enums;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace my.abp.Application.Services.Dict
{
	public class SysDictTypeService : ApplicationService,ISysDictTypeService
	{
		private readonly ISysDictTypeManager _sysDictTypeManager;
		public SysDictTypeService(ISysDictTypeManager sysDictTypeManager)
		{
			_sysDictTypeManager = sysDictTypeManager;
		}

		/// <summary>
		/// 获取字典类型分页列表
		/// </summary>
		/// <returns></returns>
		[DisplayName("获取字典类型分页列表")]
		public async Task<PagedResultDto<SysDictType>> Page(PageDictTypeInput input)
		{
			RefAsync<int> total = 0;
			var outPut = await _sysDictTypeManager.GetList(input.Code, input.Name,  input.SkipCount, input.MaxResultCount, total);

			var result = new PagedResultDto<SysDictType>();
			result.Items = outPut;
			result.TotalCount = total;
			return result;
		}

		/// <summary>
		/// 获取字典类型列表
		/// </summary>
		/// <returns></returns>
		[DisplayName("获取字典类型列表")]
		public async Task<List<SysDictType>> GetList()
		{
			return await _sysDictTypeManager.GetList();
		}

		/// <summary>
		/// 获取字典类型-值列表
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("获取字典类型-值列表")]
		public async Task<List<SysDictData>> GetDataList([FromQuery] GetDataDictTypeInput input)
		{
			return await _sysDictTypeManager.GetFirstAsync(input.Code);
		}

		/// <summary>
		/// 添加字典类型
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("添加字典类型")]
		public async Task<bool> AddDictType(AddDictTypeInput input)
		{
			return await _sysDictTypeManager.AddDictType(input.Adapt<SysDictType>());
		}

		/// <summary>
		/// 更新字典类型
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("更新字典类型")]
		public async Task UpdateDictType(UpdateDictTypeInput input)
		{
			await _sysDictTypeManager.UpdateDictType(input.Adapt<SysDictType>());
		}

		/// <summary>
		/// 删除字典类型
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[HttpPost]
		[DisplayName("删除字典类型")]
		public async Task DeleteDictType(DeleteDictTypeInput input)
		{
			await _sysDictTypeManager.DeleteDictType(input.Id);
		}

		/// <summary>
		/// 获取字典类型详情
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("获取字典类型详情")]
		public async Task<SysDictType> GetDetail([FromQuery] DictTypeInput input)
		{
			return await _sysDictTypeManager.GetDetail(input.Id);
		}

		/// <summary>
		/// 修改字典类型状态
		/// </summary>
		/// <param name="input"></param>
		/// <returns></returns>
		[DisplayName("修改字典类型状态")]
		public async Task SetStatus(DictTypeInput input)
		{
			await _sysDictTypeManager.SetStatus(input.Id,input.Status);
		}

		/// <summary>
		/// 获取所有字典集合
		/// </summary>
		/// <returns></returns>
		[DisplayName("获取所有字典集合")]
		public async Task<List<SysDictType>> GetAllDictList()
		{
			return await _sysDictTypeManager.GetAllDictList();
		}
	}
}
